package com.joven.shelltest.utils.ruleExcute;

import com.joven.shelltest.common.constant.CommonCons;
import org.springframework.stereotype.Service;

/**
 * @Author wzj
 * @Date 2023-11-22 10:28
 **/
@Service
public class NationalityRule extends AbstractRule {

    @Override
    protected <T> T convert(RuleDto dto) {
        NationalityRuleDto nationalityRuleDto = new NationalityRuleDto();
        if (dto.getAddress().startsWith(CommonCons.MATCH_ADDRESS_START)) {
            nationalityRuleDto.setNationality(CommonCons.MATCH_NATIONALITY_START);
        }
        return (T) nationalityRuleDto;
    }


    @Override
    protected <T> boolean executeRule(T t) {
        System.out.println("NationalityRule invoke!");
        NationalityRuleDto nationalityRuleDto = (NationalityRuleDto) t;
        return nationalityRuleDto.getNationality().startsWith(CommonCons.MATCH_NATIONALITY_START);
    }

    @Override
    public String getRuleName() {
        return "NationalityRule";
    }
}
